#include <iostream>
#include <vector>
#include <cmath>
#include <tbb/tick_count.h>
#include <tbb/parallel_for.h>
#include <tbb/blocked_range2d.h>

int main( int argc, char **argv )
{
    size_t n = 1 << 14;
    size_t n0 = 1 << 0;
    size_t n1 = 1 << 1;
    size_t n2 = 1 << 2;
    size_t n3 = 1 << 3;
    std::cout << " n = " << n << std::endl;
    std::cout << " n0 = " << n0 << std::endl;
    std::cout << " n1 = " << n1 << std::endl;
    std::cout << " n2 = " << n2 << std::endl;
    std::cout << " n3 = " << n3 << std::endl;

    std::vector<float> a(n * n);
    std::vector<float> b(n * n);
    tbb::tick_count t0 = tbb::tick_count::now();
    size_t grain = 16;
    //tbb::parallel_for(tbb::blocked_range2d<size_t>(0, n, 0, n),
    tbb::parallel_for(tbb::blocked_range2d<size_t>(0, n, grain, 0, n, grain),
    [&] ( tbb::blocked_range2d<size_t> r ) {
        for ( size_t i = r.cols().begin(); i < r.cols().end(); ++ i )
        {
            for ( size_t j = r.rows().begin(); j < r.rows().end(); ++ j )
            {
                b[ i * n + j ] = a[ j * n + i ];
            }
        }
    }, tbb::simple_partitioner{});

    tbb::tick_count t1 = tbb::tick_count::now();
    std::cout << "time elapsed: " << ( t1 - t0 ).seconds() * 1000 << " ms" << std::endl;

    return 0;
}

